package cn.kgc.faqs.controller;

import cn.kgc.faqs.pojo.Class;
import cn.kgc.faqs.pojo.Faqs;
import cn.kgc.faqs.pojo.ResultEntity;
import cn.kgc.faqs.service.ClassService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
public class FaqsController {

    @Resource
    ClassService classService;

    @RequestMapping("/selectFaqs")
    public ResultEntity<List<Faqs>> selectFaqs(@RequestParam(value = "title",defaultValue ="")String title){
        List<Faqs> faqsList = classService.selectAllFaqs(title);
        return ResultEntity.successWithoutData(faqsList);
    }
    @RequestMapping("/selectClass")
    public  ResultEntity<List<Class>> selectClass(){
        List<Class> classList = classService.selectAllClass();
        return ResultEntity.successWithoutData(classList);
    }
    @RequestMapping("/saveFaqs")
    public ResultEntity<Integer> saveFaqs(@RequestBody Faqs faqs){
            faqs.setCreatedate(new Date());
        Integer saveFaqs = classService.saveFaqs(faqs);
        return ResultEntity.successWithoutData(saveFaqs);
    }
    @RequestMapping("/getFaqsById")
    public  ResultEntity<Faqs> getFaqsById(Integer id){
        Faqs allById = classService.selectAllById(id);
        return ResultEntity.successWithoutData(allById);
    }



}
